package top.jandmla.shop.controller.admin;

import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import top.jandmla.shop.bean.Discount;
import top.jandmla.shop.bean.Product;
import top.jandmla.shop.bean.pojo.QueryDto;
import top.jandmla.shop.service.ProductService;
import top.jandmla.shop.utils.result.BaseResult;

/**
 * <p>
 *
 * </p>
 */
@RestController
@RequestMapping("admin/product/")
public class ProductController {

    @Autowired
    private ProductService service;

    @PostMapping("test")
    public String test(){
        return "product test is ok!";
    }

    @PostMapping("insert")
    public BaseResult<String> insertDiscount(@RequestBody Product product){
        return service.save(product) ? BaseResult.success("添加成功！")
                : BaseResult.fail(500,"添加失败！");
    }

    @PostMapping("delete")
    public BaseResult<String> deleteDiscount(@RequestBody Product product){
        return service.removeById(product.getId()) ? BaseResult.success("删除成功！")
                : BaseResult.fail(500,"删除失败！");
    }

    @PostMapping("selectPage")
    public BaseResult<IPage<Product>> selectPage(@RequestBody QueryDto<Product> dto){
        return service.selectPage(dto);
    }

    @PostMapping("update")
    public BaseResult<String> updateDiscount(@RequestBody Product product){
        return service.updateById(product) ? BaseResult.success("修改成功！")
                : BaseResult.fail(500,"修改失败！");
    }



}
